package DBtools;

import java.util.ArrayList;
import java.util.List;

public class DaoFactory {
	private static DaoFactory daoFactory = null;
	List<Object> daos  = null ;
	
	private DaoFactory(){
		daos = new ArrayList<Object>();
	}
	
	public Object getDao(Class clazz){
		if(daos==null){
			daos = new ArrayList<Object>();
		}
		Object returnObject = null; 
		for(int i=0;i<daos.size();i++){
			if(daos.get(i).getClass().equals(clazz)){
				returnObject = daos.get(i);
			}
		}
		
		if(returnObject == null){
			try{
				returnObject = clazz.newInstance();
				daos.add(returnObject);
			}catch(Exception e){
				
			}
		}
		return returnObject;
	}
	
	public static DaoFactory getInstance(){
		if(daoFactory==null){
			daoFactory = new DaoFactory();
		}
		return daoFactory;
	}
}
